<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>选择文件</title>
<link href="../../css/simple.css" type="text/css" rel="stylesheet" />
<link href="../../widgets/xloadtree/xtree.css" type="text/css" rel="stylesheet" />
<script src="../../widgets/xloadtree/xtree.js" type="text/javascript"></script>
<script src="../../widgets/xloadtree/xmlextras.js" type="text/javascript"></script>
<script src="../../widgets/xloadtree/xloadtree.js" type="text/javascript"></script>
<script src="../../widgets/sExplorer/explorer.js" type="text/javascript"></script>
<script src="../../jcx/1/full.js" charset="utf-8"></script>
<style type="text/css">
body {
	background: white;
	color: black;
}
div{
	border:1px solid #aaa;
	margin:5px;
}
.bar{
	width:100%;
	margin:0px;
	margin-bottom:5px;
}
.litem{
	height:20px;
	width:500px;
}
#treeContainer{
	width:500px; 
	height:450px;
	overflow:auto;
}

#treeContainer div {
	border:none;
}

#detail{
	width:220px;
	height:450px;
}

iframe{
	 border:none;
	 overflow:hidden;
}

#popupMenu div{
	font:normal 12px arial;
	border:none;
	background-color: #f7f7f7;
}

#popupMenu{
	position: absolute;
	left: 400px;
	top: 150px;
	min-width:10px;
	max-width:300px;
	width:auto;
	height:auto;
	z-index:100;
	
    border:1px #999 solid;
    background-color: #f7f7f7;
}
</style>
<script>
var _selectedNode;

function menuAction(node) {
    node = node||tree.getSelected();
    _selectedNode = node;
    if(!node){return;}
    var fullPath = getFullPath(node);
    
    saveSelectedPath(fullPath, node);
    
    var extname = fullPath.substr(fullPath.length-4);
    if(extname=='.jpg'||extname=='.png'||extname=='.gif'){
    	//UploadFileUtil.previewImg('file1_thumb', fullPath, 'detail');
    	UploadFileUtil.viewMedia('detail', fullPath, 'img', 200, 200);
    }else if(extname=='.mp3'){
    	UploadFileUtil.viewMedia('detail', fullPath, 'audio');
    }else{
    	$E('detail').innerHTML = '';
    }
}

function setOnItemDbClick(fun){
	
}

function getUploadDestDir(){
	var fullPath = getSelectedPath();
	var isDir = fullPath.charAt(fullPath.length-1)=='/';
	if(isDir){
		return fullPath;
	}else{
		return StringUtil.getDir(fullPath);
	}
}

function getSelectedPath(){
	var e = document.getElementById('address');
	return e.innerHTML;;
}

function saveSelectedPath(fullPath, node){
	if(node.src){
		if(fullPath.charAt(fullPath.length-1)!='/'){
			fullPath += '/';
		}
	}
	
	var e = document.getElementById('address');
	e.innerHTML = fullPath;
}

function uploadCallback(result){
	if(!result){
		return;
	}
	if(result.success!='Y'){
		alert('上传失败！');
		return;
	}
	$E(result.inputId+'_upload').value = Js.json2str(result);
	
	afterLoad = function(){
		var node = getChildNode(_selectedNode, StringUtil.getFileName(result.path));
		menuAction(node);
	}
	_selectedNode.reload();
}

function resize1(){
	var w = Win.width();
	w = w - 220 - 40;
	$E('treeContainer').style.width = w+'px';
}

function load1() {
	resize1();
	rootPath = _getRootPath()||'/';
	initTree();
	setItemMenu();
}

function _getRootPath(){
	var qstr = location.hash.substr(1);
	return qstr;
}

function delNode(){
	var del_submit = function(){
		var node = getNode(popupMenuTreeNodeId);
		var parentNode = node.parentNode;
		var filePath = getFullPath(node);
		var DEL_URL = URL_ROOT+"/fileInfo/delete.json";
		var values = {"filePath":filePath};
		ajaxRequest(DEL_URL, values, function(result){
			parentNode.reload();
			menuAction(parentNode);
		},false,true);
	}
	var msg = '您确定要删除吗？';
	var name = $E('webfx-tree-object-'+popupMenuTreeNodeId+'-anchor').innerHTML;
	if(name){
		msg = '您确定要删除<b style="color:red">'+name+'</b>吗？'
	}
	confirm(msg, del_submit);
}

function filterNodes(){
	$E('popupMenu').style.display='none';
	var keyword = prompt('输入关键字:');
	if(keyword){
		keyword = keyword.toLowerCase();	
	}
	var node = getNode(popupMenuTreeNodeId);
	var nodelist = node.childNodes;
	for(var i=0;i<nodelist.length;i++){
		var node1 = nodelist[i];
		if(keyword && node1.text.toLowerCase().indexOf(keyword)==-1){
			$E(node1.id).style.display = 'none';
		}else{
			$E(node1.id).style.display = '';
		}
	}
}

</script>
</head>

<body onload="load1()" onresize="resize1()">
	<div id="popupMenu" style="display:none;">
		<div><a href="javascript:filterNodes();">过滤子节点</a></div>
		<div><a href="javascript:delNode();">删除</a></div>
	</div>
	
	<div class="fl bar">
	    <div class="fl" id="treeContainer"></div>
	    <div class="fl" id="detail">
	    	<img id="file1_thumb"></img>
	    </div>
	  	<div class="cb"></div>
	</div>
	
	<div class="fl bar">
	    <div class="fl">地址：</div>
	    <div class="fl litem" id="address">&nbsp;</div>
	    <div class="cb"></div>
	</div>
	
	<div class="fl bar">
	    <div class="fl" id="upload">
	        <p style="height: 28px; width: 300px; overflow: hidden; scrolling: no; padding: 0px; margin: 0px;text-align: left">
	            <iframe src="../../file/upfile.xhtml?inputId=file1&keepName=Y" name="uploadFrame" width="100%" height="100%" scrolling="no"></iframe>
	            <input id="file1_upload" name="file1_upload" value="" type="hidden" />
	        </p>
		</div>
	    <div class="cb"></div>
	</div>

</body>
</html>
